﻿#region

using Lab.Common.Dto;
using Lab.Server.Domain;

#endregion

namespace Lab.Server.Application {
    public class Translator {
        public static Vacancy TranslateToDomain(DtoVacancy dtoVacancy) {
            return new Vacancy {
                                   Id = dtoVacancy.Id,
                                   Name = dtoVacancy.Name,
                                   OpenVacancy = dtoVacancy.OpenVacancy,
                                   Location = dtoVacancy.Location,
                                   ExpectedLevelOfSalary = dtoVacancy.ExpectedLevelOfSalary,
                                   Skills = dtoVacancy.Skills.ConvertAll(TranslateToDomain),
                                   KindOfActivity = TranslateToDomain(dtoVacancy.KindOfActivity),
                                   Employer = TranslateToDomain(dtoVacancy.Employer),
                                   IsOpen = dtoVacancy.IsOpen
                               };
        }

        public static Employer TranslateToDomain(DtoEmployer dtoEmployer) {
            return new Employer {
                                    Id = dtoEmployer.Id,
                                    Name = dtoEmployer.Name,
                                    Address = dtoEmployer.Address,
                                    TelephoneNumber = dtoEmployer.TelephoneNumber,
                                    KindOfActivities = dtoEmployer.KindOfActivities.ConvertAll(TranslateToDomain)
                                };
        }

        public static KindOfActivity TranslateToDomain(DtoKindOfActivity dtoKindOfActivity) {
            return new KindOfActivity { Id = dtoKindOfActivity.Id, Description = dtoKindOfActivity.Description };
        }

        public static Skill TranslateToDomain(DtoSkill dtoSkill) {
            return new Skill { Id = dtoSkill.Id, Description = dtoSkill.Description };
        }

        public static Applicant TranslateToDomain(DtoApplicant dtoApplicant) {
            return new Applicant {
                                     Id = dtoApplicant.Id,
                                     Surname = dtoApplicant.Surname,
                                     Name = dtoApplicant.Name,
                                     MiddleName = dtoApplicant.MiddleName,
                                     KindOfActivity = TranslateToDomain(dtoApplicant.KindOfActivity),
                                     PlaceOfResidence = dtoApplicant.PlaceOfResidence,
                                     Skills = dtoApplicant.Skills.ConvertAll(TranslateToDomain)
                                 };
        }

        public static Deal TranslateToDomain(DtoDeal dtoDeal) {
            return new Deal {
                                Applicant = TranslateToDomain(dtoDeal.Applicant),
                                Employer = TranslateToDomain(dtoDeal.Employer),
                                Vacancy = TranslateToDomain(dtoDeal.Vacancy)
                            };
        }

        public static DtoDeal TranslateToDto(Deal deal) {
            return new DtoDeal {
                                   Applicant = TranslateToDto(deal.Applicant),
                                   Employer = TranslateToDto(deal.Employer),
                                   Vacancy = TranslateToDto(deal.Vacancy)
                               };
        }

        public static DtoVacancy TranslateToDto(Vacancy vacancy) {
            return new DtoVacancy {
                                      Id = vacancy.Id,
                                      Name = vacancy.Name,
                                      OpenVacancy = vacancy.OpenVacancy,
                                      Location = vacancy.Location,
                                      ExpectedLevelOfSalary = vacancy.ExpectedLevelOfSalary,
                                      Skills = vacancy.Skills.ConvertAll(TranslateToDto),
                                      KindOfActivity = TranslateToDto(vacancy.KindOfActivity),
                                      Employer = TranslateToDto(vacancy.Employer),
                                      IsOpen = vacancy.IsOpen
                                  };
        }

        public static DtoEmployer TranslateToDto(Employer employer) {
            return new DtoEmployer {
                                       Id = employer.Id,
                                       Name = employer.Name,
                                       Address = employer.Address,
                                       TelephoneNumber = employer.TelephoneNumber,
                                       KindOfActivities = employer.KindOfActivities.ConvertAll(TranslateToDto)
                                   };
        }

        public static DtoKindOfActivity TranslateToDto(KindOfActivity kindOfActivity) {
            return new DtoKindOfActivity { Id = kindOfActivity.Id, Description = kindOfActivity.Description };
        }

        public static DtoSkill TranslateToDto(Skill skill) {
            return new DtoSkill { Id = skill.Id, Description = skill.Description };
        }

        public static DtoApplicant TranslateToDto(Applicant applicant) {
            return new DtoApplicant {
                                        Id = applicant.Id,
                                        Surname = applicant.Surname,
                                        Name = applicant.Name,
                                        MiddleName = applicant.MiddleName,
                                        KindOfActivity = TranslateToDto(applicant.KindOfActivity),
                                        PlaceOfResidence = applicant.PlaceOfResidence,
                                        Skills = applicant.Skills.ConvertAll(TranslateToDto)
                                    };
        }
    }
}